part of '../../../repository.dart';

const _kYookassaTransactionRevocationInfoRefundedAmountKey = 'refunded_amount';
const _kYookassaTransactionRevocationInfoTimeKey = 'time';

class _YookassaTransactionRevocationInfoDto extends Equatable {
  const _YookassaTransactionRevocationInfoDto._internal({
    required this.timeDto,
    required this.refundedAmountDto,
  });

  final ApiTimeDto timeDto;
  final ApiMoneyAmountDto refundedAmountDto;

  @override
  List<Object?> get props {
    return [
      timeDto,
      refundedAmountDto,
    ];
  }

  factory _YookassaTransactionRevocationInfoDto.fromJson(Map<String, dynamic> json) {
    final timeString = json[_kYookassaTransactionRevocationInfoTimeKey];
    final timeDto = ApiTimeDto.fromString(timeString);

    final refundedAmountJson =
        json[_kYookassaTransactionRevocationInfoRefundedAmountKey] as Map<String, dynamic>;
    final refundedAmountDto = ApiMoneyAmountDto.fromJson(refundedAmountJson);

    return _YookassaTransactionRevocationInfoDto._internal(
      timeDto: timeDto,
      refundedAmountDto: refundedAmountDto,
    );
  }

  YookassaTransactionRevocationInfo toEntity() {
    return YookassaTransactionRevocationInfo(
      time: timeDto.toEntity(),
      refundedAmount: refundedAmountDto.toEntity(),
    );
  }
}
